import time
#导入时间

data = [
    ["  类别  "," 账户  ","金额","   时间   ","  说明  "],
    ["吃饭支出","交通银行","247.0","2016-03-02","家庭聚餐"],
    ["吃饭支出","现金","12345.0","2016-03-15","开工资了"],
    ["工资收入","现金","1998.0","2016-04-02","买衣服"],
    ["服装支出","现金","325.0","2016-06-18","朋友聚餐"],
    ["股票收入","工商银行","8000.0","2016-10-28","股票大涨"],
    ["股票收入","工商银行","5000.0","2016-10-28","股票又大涨"],
    ["工资收入","交通银行","5000.0","2016-10-28","又开工资了"],
    ["礼金支出","现金","5000.0","2016-10-28","朋友结婚"],
    ["其他支出","现金","1560.0","2016-10-29","丢钱了"],
    ["交通支出","交通银行","2300.0","2016-10-29","油价还在涨啊"],
    ["吃饭支出","工商银行","1000.0","2016-10-29","又吃饭"],
    ["工资收入","现金","1000.0","2016-10-30","开资"],
    ["交通支出","现金","2000.0","2016-10-30","机票好贵"],
    ["工资收入","现金","5000.0","2016-10-30","又开资"],
]

#定义权限
root = 0

#输入账号密码
while True:
    print("欢迎来到 House  Wife 家庭记账通系统".center(50, "-"))
    account=input("请输入账号：")
    password=input("请输入密码：")
    if password == "123456":
        if account == "admin":
            root = 1
            break
        elif account == "lisi":
            root = 2
            break
        else:
            print("账号错误，请重新输入")
    else:
        print("账号或密码错误，请重新输入")

while True:
#管理员账户
    if root == 1:
        print("-".center(50, "-"))
        print("1.添加账务  2.编辑账务  3.删除账务  4.查询账务  5.退出系统")
        function = input("请输入要操作的功能序号[1-5]:")
# 添加账务
        if function == "1":
            print("-".center(50, "-"))
            category = input("请输入类别:")
            account = input("请输入账户:")
            money = input("请输入金额:")
            time = input("请输入时间:")
            illustrate = input("请输入说明:")
            data.append([category, account, money,time,illustrate])
            print("添加账务成功!")
#编辑账务
        elif function == "2":
            while True:
                print("-".center(50, "-"))
                for a, b in enumerate(data):  # 为data添加ID
                    print(a, b)
                ID1 = input("请输入ID:")
                if ID1.isdigit():
                    ID1 = int(ID1)
                    if ID1 >= len(data)-1 or ID1 == 0:
                        print("输入错误，请重新输入！")
                    else:
                        choice = input("请输入编辑的对象（类别/账户/金额/时间/说明）:")
                        if choice == "q" or choice == "Q":
                            break
                        elif choice == "类别":
                            data[ID1][0] = input("请输入新的类别:")
                            print("修改成功！")
                            break
                        elif choice == "账户":
                            data[ID1][1] = input("请输入新的账户:")
                            print("修改成功！")
                            break
                        elif choice == "金额":
                            data[ID1][2] = input("请输入新的金额:")
                            print("修改成功！")
                            break
                        elif choice == "时间":
                            data[ID1][3] = input("请输入新的时间:")
                            print("修改成功！")
                            break
                        elif choice == "说明":
                            data[ID1][4] = input("请输入新的说明:")
                            print("修改成功！")
                            break
                        else:
                            print("输入错误，请重新输入！")
                elif ID1 == "q" or ID1 == "Q":
                    break
                else:
                    print("输入错误，请重新输入！")
#删除账务
        elif function == "3":
            print("-".center(50, "-"))
            for a, b in enumerate(data):  # 为data添加ID
                ID1 = input("请输入ID:")
                if ID1.isdigit():
                    ID1 = int(ID1)
                    if ID1 >= len(data) or ID1 == 0:
                        print("输入错误，请重新输入！")
                    else:
                        data.pop(ID1)
                        print("删除成功")
                        break
                elif ID1 == "q" or ID1 == "Q":
                    break
                else:
                    print("输入错误，请重新输入！")
#查询账务
        elif function == "4":
            while True:
                print("-".center(50, "-"))
                print("1、查询所有 2、按条件查询")
                choice = input(">>>:")
                if choice == "1":
                    print("-".center(50, "-"))
                    for a, b in enumerate(data):  # 为data添加ID
                        print(a, b)
                elif choice == "2":
                    while True:
                        print("-".center(50, "-"))
                        condition = input("请输入查询条件（ID/类别/账户/金额/时间）:")
                        if condition == "q" or condition == "Q":
                            break
                        elif condition == "ID":   #按ID查询
                            for a, b in enumerate(data):  # 为data添加ID
                                ID1 = input("请输入ID:")
                                if ID1.isdigit():
                                    ID1 = int(ID1)
                                    if ID1 >= len(data) - 1 or ID1 == 0:
                                        print("输入错误，请重新输入！")
                                    else:
                                        print(data[0])
                                        print(data[ID1])
                        elif condition == "类别":
                            category = input("请输入类别:")
                            flag = 0
                            for i in data:
                                if i[0] == category:
                                    flag = 1
                                    print([i[0], i[1], i[2],i[3],i[4]])
                            if flag == 0:
                                print("输入错误，请重新输入！")
                        elif condition == "账户":
                            account = input("请输入账户:")
                            flag = 0
                            for i in data:
                                if i[1] == account:
                                    flag = 1
                                    print([i[0], i[1], i[2], i[3], i[4]])
                            if flag == 0:
                                print("输入错误，请重新输入！")
                        elif condition == "金额":
                            money = input("请输入金额:")
                            flag = 0
                            for i in data:
                                if i[2] == money:
                                    flag = 1
                                    print([i[0], i[1], i[2], i[3], i[4]])
                            if flag == 0:
                                print("输入错误，请重新输入！")
                        elif condition == "时间":
                            time = input("请输入时间:")
                            flag = 0
                            for i in data:
                                if i[3] == time:
                                    flag = 1
                                    print([i[0], i[1], i[2], i[3], i[4]])
                            if flag == 0:
                                print("输入错误，请重新输入！")
                        else:
                            print("输入错误，请重新输入！")
                elif choice == "q" or choice == "Q":
                    break
                else:
                    print("输入错误，请重新输入！")
#退出系统
        elif function == "5":
            print("-".center(50, "-"))
            print("退出成功，再见！")
            print("-".center(50, "-"))
            break
        else:
            print("输入错误，请重新输入")
#普通用户
    elif root == 2:
        print("-".center(50, "-"))
        print("1、查询所有 2、按条件查询")
        choice = input(">>>:")
        if choice == "1":
            print("-".center(50, "-"))
            for a, b in enumerate(data):  # 为data添加ID
                print(a, b)
        elif choice == "2":
            while True:
                print("-".center(50, "-"))
                condition = input("请输入查询条件（ID/类别/账户/金额/时间）:")
                if condition == "q" or condition == "Q":
                    break
                elif condition == "ID":  # 按ID查询
                    for a, b in enumerate(data):  # 为data添加ID
                        ID1 = input("请输入ID:")
                        if ID1.isdigit():
                            ID1 = int(ID1)
                            if ID1 >= len(data) - 1 or ID1 == 0:
                                print("输入错误，请重新输入！")
                            else:
                                print(data[0])
                                print(data[ID1])
                elif condition == "类别":
                    category = input("请输入类别:")
                    flag = 0
                    for i in data:
                        if i[0] == category:
                            flag = 1
                            print([i[0], i[1], i[2], i[3], i[4]])
                    if flag == 0:
                        print("输入错误，请重新输入！")
                elif condition == "账户":
                    account = input("请输入账户:")
                    flag = 0
                    for i in data:
                        if i[1] == account:
                            flag = 1
                            print([i[0], i[1], i[2], i[3], i[4]])
                    if flag == 0:
                        print("输入错误，请重新输入！")
                elif condition == "金额":
                    money = input("请输入金额:")
                    flag = 0
                    for i in data:
                        if i[2] == money:
                            flag = 1
                            print([i[0], i[1], i[2], i[3], i[4]])
                    if flag == 0:
                        print("输入错误，请重新输入！")
                elif condition == "时间":
                    time = input("请输入时间:")
                    flag = 0
                    for i in data:
                        if i[3] == time:
                            flag = 1
                            print([i[0], i[1], i[2], i[3], i[4]])
                    if flag == 0:
                        print("输入错误，请重新输入！")
                else:
                    print("输入错误，请重新输入！")
        elif choice == "q" or choice == "Q":
            print("-".center(50, "-"))
            print("退出成功，再见！")
            print("-".center(50, "-"))
            break
        else:
            print("输入错误，请重新输入！")


























